package com.mz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.mz.common.dto.PaginationVo;
import com.mz.common.dto.R;
import com.mz.common.utils.PageDataHandlerUtils;
import com.mz.entity.UmsUserInfo;
import com.mz.entity.vo.*;
import com.mz.service.UmsUserInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (UmsUserInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:38:41
 */
@RestController
@RequestMapping("/umsUserInfo")
public class UmsUserInfoController  {
    /**
     * 服务对象
     */
    @Resource
    private UmsUserInfoService umsUserInfoService;

    /**
     * 获取 “管理系统的账号” 分页列表
     *
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getUserPagination(PaginationVo paginationVo, UserQuery userQuery) throws Exception {
        IPage page = umsUserInfoService.getUserList( paginationVo, userQuery );
        return PageDataHandlerUtils.toR(page);
    }


    /**
     * 获取 “小程序会员账号” 分页列表
     * */
    @GetMapping("/members/pagination")
    public R getMemberPagination( PaginationVo paginationVo, MemberQuery memberQuery ) throws Exception {
        IPage page = umsUserInfoService.getMemberList( paginationVo, memberQuery );
        return PageDataHandlerUtils.toR(page);
    }

    /**
     * 新增数据
     *
     * @return 新增结果
     */
    @PostMapping
    public R addUser(@RequestBody @Valid  UserVo userVo)  throws Exception {

        umsUserInfoService.addUser( userVo );
        return R.ok();
    }

    /**
     * 修改数据
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody UserVo userVo  )  throws Exception {

        umsUserInfoService.update(userVo);
        return R.ok();
    }

    /**
     * 更新密码
     * */
    @PutMapping("/password")
    public R updatePassword( @RequestBody @Valid PasswordVo passwordVo ) throws Exception {
        umsUserInfoService.updatePassword( passwordVo );
        return R.ok();
    }

    /**
     * 锁定账号、解锁账号
     * */
    @PutMapping("/lockOrUnlock")
    public R lockAndUnlock( @RequestBody @Valid MemberLockVo memberLockVo ) throws Exception {

        umsUserInfoService.lockAndUnlock(memberLockVo);
        return R.ok();
    }


    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/remove")
    public R removeUser(@RequestBody List<Long> idList) throws Exception {

        umsUserInfoService.removeUser( idList );
        return R.ok();
    }
}

